<?php

namespace app\admin\validate;

use think\Validate;

class Products extends Validate
{
    /**
     * 验证规则
     */
    public $rule = [
        'goods_id'   => 'require|number',
        'costprice'  => 'float',
        'mktprice'   => 'float',
        //'price'      => 'require|float',
        'stock'      => 'regex:/^-?[0-9]\d*$/',
        'sn'         => 'unique:products',
    ];
    /**
     * 提示消息
     */
    public $message = [
        'goods_id.require' => '商品ID不能为空',
        'goods_id.number'  => '商品ID非法',
        'costprice'        => '请输入正确的成本价',
        'mktprice'         => '请输入正确的市场价',
        //'price.float'      => '请输入正确的销售价',
        //'price.require'    => '销售价不能为空',
        'stock.regex'      => '库存非法',
        'sn.unique'        => '货品编号不能重复',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'edit' => ['goods_id', 'costprice', 'mktprice', 'price', 'stock', 'sn' => 'unique:products,sn^id'],
    ];



    
}
